package io.noties.markwon.base.image.span

import io.noties.markwon.base.MarkwonConfiguration
import io.noties.markwon.base.RenderProps
import io.noties.markwon.base.SpanFactory
import io.noties.markwon.base.image.AsyncDrawable
import io.noties.markwon.base.image.ImageProps

class ImageSpanFactory : SpanFactory {
    override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {
        return AsyncDrawableSpan(
            configuration.theme,
            AsyncDrawable(
                ImageProps.DESTINATION.require(props),
                configuration.asyncDrawableLoader(),
                configuration.imageSizeResolver(),
                ImageProps.IMAGE_SIZE[props]
            ),
            AsyncDrawableSpan.ALIGN_BOTTOM,
            ImageProps.REPLACEMENT_TEXT_IS_LINK[props, false]
        )
    }
}